package com.market.util;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Utils {
	public Map<String,String> readXml(){
		Map<String, String> rXml = new HashMap<String, String>();
		try{
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db = dbf.newDocumentBuilder();
		String path = "build\\classes\\com\\market\\util\\";
		File file=new File(path+"DbInfo.xml"); 
		Document doc = db.parse(file);
		NodeList products=doc.getElementsByTagName("database");
		for (int i = 0; i < products.getLength(); i++){
			rXml.put("poolName", doc.getElementsByTagName("poolName").item(i).getFirstChild().getNodeValue());
			rXml.put("drivers", doc.getElementsByTagName("drivers").item(i).getFirstChild().getNodeValue());
			rXml.put("url", doc.getElementsByTagName("url").item(i).getFirstChild().getNodeValue());
			rXml.put("username", doc.getElementsByTagName("username").item(i).getFirstChild().getNodeValue());
			rXml.put("password", doc.getElementsByTagName("password").item(i).getFirstChild().getNodeValue());
			rXml.put("max", doc.getElementsByTagName("max").item(i).getFirstChild().getNodeValue());
		}
		}catch(Exception e){
			e.printStackTrace();
		}
		System.out.println(rXml.size());
		return rXml;
	}
}
